package personal.lijun.skeleton.springcloud.serviceprovider.service.controller;

import org.springframework.web.bind.annotation.*;
import personal.lijun.skeleton.spring.springcloud.serviceprovider.data.Event;
import personal.lijun.skeleton.spring.springcloud.serviceprovider.service.EventsService;
import personal.lijun.skeleton.springcloud.common.data.ApiResultPrimitiveValue;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: lijun@sstcsoft.com
 * @Date: 2019-10-12 15:42
 */
@RestController
@RequestMapping("/event")
public class EventsController {

    @Resource
    private EventsService eventsService;
    /**
     * 保存用户事件
     *
     * @param event 用户信息
     */
    @RequestMapping(value = "/save",method = {RequestMethod.POST})
    public Event save(@RequestBody Event event){
        return eventsService.save(event);
    }

    /**
     * 增加一个新用户事件
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/addNewEvents",method = {RequestMethod.POST})
    public Event addNewEvents(@RequestBody Event record){
        return eventsService.addNewEvents(record);
    }

    /**
     * 更新指定用户事件信息
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/updateEvents",method = {RequestMethod.POST})
    public Event updateEvents(@RequestBody Event record) {
        return eventsService.updateEvents(record);
    }

    /**
     * 根据id删除指定用户事件
     *
     * @param id 用户事件id
     * @return
     */
    @RequestMapping(value = "/deleteEventsById",method = {RequestMethod.POST}, produces = {"application/json;charset=UTF-8"})
    public ApiResultPrimitiveValue<Integer> deleteEventsById(@RequestParam("id") Long id){
        Integer deleteRow = eventsService.deleteEventsById(id);
        return new ApiResultPrimitiveValue<Integer>(deleteRow);
    }

    /**
     * 查询指定id的用户事件信息
     *
     * @param id 用户事件id
     * @return
     */
    @RequestMapping(value = "/getEventsById",method = {RequestMethod.GET})
    public Event  getEventsById(@RequestParam("id")Long id){
        return eventsService.getEventsById(id);
    }

    /**
     * 查询指定用户的事件
     *
     * @param userId 用户id
     * @return 事件列表
     */
    @RequestMapping(value = "/findForUser",method = {RequestMethod.GET})
    public List<Event> findForUser(long userId) {
        return eventsService.findForUser(userId);
    }

    @RequestMapping(value = "/getEvents",method = {RequestMethod.GET})
    public List<Event> getEvents(){
        return eventsService.getEvents();
    }
}
